<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>nih: Binary Trees</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nih
   &#160;<span id="projectnumber">0.5</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('group__bintree.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#nested-classes">Classes</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Binary Trees</div>  </div>
</div>
<div class="contents">
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="nested-classes"></a>
Classes</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structnih_1_1_bintree__node.html">nih::Bintree_node</a></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structnih_1_1cuda_1_1_bintree__context.html">nih::cuda::Bintree_context</a></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structnih_1_1cuda_1_1_bintree__gen__context.html">nih::cuda::Bintree_gen_context</a></td></tr>
<tr><td colspan="2"><h2><a name="func-members"></a>
Functions</h2></td></tr>
<tr><td class="memTemplParams" colspan="2">template&lt;typename Tree , typename Integer &gt; </td></tr>
<tr><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__bintree.html#gad76a50ae08ab4d525f748a7cbcc0fb6e">nih::cuda::generate</a> (Bintree_gen_context &amp;context, const uint32 n_codes, const Integer *codes, const uint32 bits, const uint32 max_leaf_size, const bool keep_singletons, Tree &amp;tree)</td></tr>
</table>
<hr/><h2>Function Documentation</h2>
<a class="anchor" id="gad76a50ae08ab4d525f748a7cbcc0fb6e"></a><!-- doxytag: member="nih::cuda::generate" ref="gad76a50ae08ab4d525f748a7cbcc0fb6e" args="(Bintree_gen_context &amp;context, const uint32 n_codes, const Integer *codes, const uint32 bits, const uint32 max_leaf_size, const bool keep_singletons, Tree &amp;tree)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Tree , typename Integer &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">void nih::cuda::generate </td>
          <td>(</td>
          <td class="paramtype">Bintree_gen_context &amp;&#160;</td>
          <td class="paramname"><em>context</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const uint32&#160;</td>
          <td class="paramname"><em>n_codes</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const Integer *&#160;</td>
          <td class="paramname"><em>codes</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const uint32&#160;</td>
          <td class="paramname"><em>bits</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const uint32&#160;</td>
          <td class="paramname"><em>max_leaf_size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const bool&#160;</td>
          <td class="paramname"><em>keep_singletons</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Tree &amp;&#160;</td>
          <td class="paramname"><em>tree</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Generate a binary tree from a set of sorted integers, splitting the set top-down at each occurrence of a bit set to 1. In practice, if the integers are seen as Morton codes, this algorithm generates a middle-split k-d tree.</p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">context</td><td>the generation context </td></tr>
    <tr><td class="paramname">n_codes</td><td>number of entries in the input set of codes </td></tr>
    <tr><td class="paramname">codes</td><td>input set of codes </td></tr>
    <tr><td class="paramname">bits</td><td>number of bits per code </td></tr>
    <tr><td class="paramname">max_leaf_size</td><td>maximum target number of entries per leaf </td></tr>
    <tr><td class="paramname">keep_singletons</td><td>mark whether to keep or suppress singleton nodes in the output tree </td></tr>
    <tr><td class="paramname">tree</td><td>output tree</td></tr>
  </table>
  </dd>
</dl>
<p>The Tree template parameter has to provide the following interface:</p>
<div class="fragment"><pre class="fragment"> <span class="keyword">struct </span>Tree
 {
    <span class="keywordtype">void</span> reserve_nodes(<span class="keyword">const</span> uint32 n);  <span class="comment">// reserve space for n nodes</span>
    <span class="keywordtype">void</span> reserve_leaves(<span class="keyword">const</span> uint32 n); <span class="comment">// reserve space for n leaves</span>

    Context get_context();             <span class="comment">// get a context to write nodes/leaves</span>

    <span class="keyword">struct </span>Context
    {
        <span class="keywordtype">void</span> write_node(
           <span class="keyword">const</span> uint32 node,          <span class="comment">// node to write</span>
           <span class="keyword">const</span> <span class="keywordtype">bool</span>   left_child,    <span class="comment">// specify whether the node has a left child</span>
           <span class="keyword">const</span> <span class="keywordtype">bool</span>   right_child,   <span class="comment">// specify whether the node has a right child</span>
           <span class="keyword">const</span> uint32 offset,        <span class="comment">// child offset</span>
           <span class="keyword">const</span> uint32 skip_node,     <span class="comment">// skip node</span>
           <span class="keyword">const</span> uint32 level,         <span class="comment">// split level</span>
           <span class="keyword">const</span> uint32 begin,         <span class="comment">// node range begin</span>
           <span class="keyword">const</span> uint32 end,           <span class="comment">// node range end</span>
           <span class="keyword">const</span> uint32 split_index);  <span class="comment">// split index</span>

        <span class="keywordtype">void</span> write_leaf(
           <span class="keyword">const</span> uint32 index,         <span class="comment">// leaf to write</span>
           <span class="keyword">const</span> uint32 begin,         <span class="comment">// leaf range begin</span>
           <span class="keyword">const</span> uint32 end);          <span class="comment">// leaf range end</span>
    };
 };
</pre></div><p>The following code snippet shows how to use this builder:</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include &lt;nih/bintree/cuda/bintree_gen.h&gt;</span>
<span class="preprocessor"> #include &lt;<a class="code" href="bintree__context_8h.html" title="Defines a simple binary tree context implementation to be used with the Bintree generate() function...">nih/bintree/cuda/bintree_context.h</a>&gt;</span>
<span class="preprocessor"> #include &lt;<a class="code" href="morton_8h.html" title="Defines some general purpose algorithms.">nih/bits/morton.h</a>&gt;</span>

 <span class="keyword">const</span> uint32 n_points = 1000000;
 thrust::device_vector&lt;Vecto3f&gt; points( n_points );
 ... <span class="comment">// generate a bunch of points here</span>

 <span class="comment">// compute their Morton codes</span>
 thrust::device_vector&lt;uint32&gt; codes( n_points );
 thrust::transform(
     points.begin(),
     points.begin() + n_points,
     codes.begin(),
     morton_functor&lt;uint32&gt;() );

 <span class="comment">// sort them</span>
 thrust::sort( codes.begin(), codes.end() );

 <span class="comment">// allocate storage for a binary tree...</span>
 thrust::device_vector&lt;Bintree_node&gt; nodes;
 thrust::device_vector&lt;uint2&gt;        leaves;

 Bintree_context tree( nodes, leaves );

 <span class="comment">// ...and generate it!</span>
 Bintree_gen_context gen_context;
 <a class="code" href="group__bintree.html#gad76a50ae08ab4d525f748a7cbcc0fb6e">cuda::generate</a>(
     gen_context,
     n_points,
     thrust::raw_pointer_cast( &amp;codes.front() ),
     30u,
     16u,
     <span class="keyword">false</span>,
     tree );
</pre></div> 
</div>
</div>
</div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">Generated on Thu Dec 15 2011 11:56:21 for nih by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
